//
//  ContentViewController.m
//  F50
//
//  Created by zack on 15/5/22.
//  Copyright (c) 2015年 ZACK. All rights reserved.
//

#import "ContentViewController.h"

@interface ContentViewController ()<UITextViewDelegate>
{
    UITextView *_textView;
    UILabel *placeLab; // 假的placeholder
}

@end

@implementation ContentViewController
- (void)createBackground
{
    UIView *nav_bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 64)];
    nav_bg.backgroundColor = RGB(59, 107, 178);
    [self.view addSubview:nav_bg];
    
    
    //中间标题
    UILabel *  nav_title=[[UILabel alloc] initWithFrame:CGRectMake(WIDTH/2 - 80, 20, 160, 40)];
    nav_title.text=@"介绍自己";
    nav_title.textAlignment = NSTextAlignmentCenter;
    nav_title.font=[UIFont boldSystemFontOfSize:20];
    nav_title.textColor=[UIColor whiteColor];
    nav_title.backgroundColor=[UIColor clearColor];
    [nav_bg addSubview:nav_title];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(20, 32, 15, 18);
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [nav_bg addSubview:backBtn];
    
    
    UIButton *senderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    senderBtn.frame = CGRectMake(WIDTH - 50, 23, 40, 40);
    [senderBtn setTitle:@"发送" forState:UIControlStateNormal];
    //    [senderBtn setContentMode:UIViewContentModeCenter];
    [senderBtn addTarget:self action:@selector(send) forControlEvents:UIControlEventTouchUpInside];
    [nav_bg addSubview:senderBtn];
    
    
    _textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, 200)];
    _textView.font = [UIFont systemFontOfSize:14];
    //    _textView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    _textView.backgroundColor = [UIColor whiteColor];
    //    textView.hidden = NO;
    _textView.delegate = self;
    
    
    
    
    [self.view addSubview:_textView];
    
    
    placeLab = [[UILabel alloc]initWithFrame:CGRectMake(5, 8, WIDTH, 20)];
    placeLab.text = @"请用一句话介绍自己";
    placeLab.enabled = NO;//lable必须设置为不可用
    placeLab.backgroundColor = [UIColor clearColor];
    placeLab.font = [UIFont systemFontOfSize:14];
    
    [_textView addSubview:placeLab];
    
}
-(void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length == 0) {
        placeLab.text = @"请用一句话介绍自己";
    }else{
        placeLab.text = @"";
    }
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self createBackground];
}
- (void)send{
    [self.view endEditing:YES];
    
    
    
    
    NSDictionary * date = [[NSDictionary  alloc]initWithObjectsAndKeys:[USER_DEFAULT objectForKey:@"token"],@"token",_textView.text,@"content",nil];
    NSDictionary *pram = [[NSDictionary alloc]initWithObjectsAndKeys:@"member",@"class",@"chcontent",@"func",date,@"param", nil];
    
    [[AFCustomObject shareAFCustomObject] doRequestActionWithParams:pram success:^(NSDictionary *result) {
        NSLog(@"%@",result);
        NSLog(@"%@",[result objectForKey:@"errMsg"]);
        [USER_DEFAULT setObject:_textView.text forKey:@"content"];
        if (self.succeedBlock) {
            self.succeedBlock(_textView.text);
        }
        
        [self back];
        
    } fail:^{
        
    }];
    
    
    
    
    
}

- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
